#include "helper/sqlite/Transaction.h"

#include "helper/sqlite/IDB.h"
#include "helper/sqlite/Statement.h"

namespace helper {
namespace sqlite {

Transaction::Transaction(helper::sqlite::IDB & db)
:_db(db)
{
}
Transaction::~Transaction(){
}

std::error_code Transaction::_begin() {
  return action("BEGIN");
}
std::error_code Transaction::_commit()  {
  return action("COMMIT");
}
std::error_code Transaction::_rollback() {
  return action("ROLLBACK");
}

std::error_code Transaction::action(const char * sql) {
  std::error_code ec;
  auto && stmt = _db.createStatement(sql, ec);
  if(!ec && stmt){
    return stmt->action().errorCode();
  }
  return ec;
}

}//namespace sqlite
}//namespace helper:
